using System;
using System.Collections.Generic;
using System.Linq;
namespace DIS_WEB_Client.Controllers
{
	#region using
	using System;
	using System.Web.Mvc;
	using System.Web.Security;
	using System.Collections.Generic;
	using DIS_WEB_Client.Helpers;
    using DIS_WEB_Client.ViewModels;
	using System.IO;
	using System.Web;
    using DIS_Web_Client.DIS_WS_BusinessLayer;
    using DIS_WEB_Client.ShoppingCartModule;
	#endregion
	public abstract class BaseController : Controller
	{
		protected string RenderPartialViewToString()
		{
			return RenderPartialViewToString(null, null);
		}

		protected string RenderPartialViewToString(string viewName)
		{
			return RenderPartialViewToString(viewName, null);
		}

		protected string RenderPartialViewToString(string viewName, object model)
		{
			if (string.IsNullOrEmpty(viewName))
				viewName = ControllerContext.RouteData.GetRequiredString("action");
			ViewData.Model = model;
			using (StringWriter sw = new StringWriter())
			{
				ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
				ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
				viewResult.View.Render(viewContext, sw);
				return sw.GetStringBuilder().ToString();
			}
		}

        protected bool AuthenticateSession(ref string username)
        {
            HttpCookie SlmSessionId = new HttpCookie("SLMFSessionId");
            SlmSessionId = HttpContext.Request.Cookies["SLMFSessionId"];
            if (SlmSessionId != null && SlmSessionId.Value != "" &&
                 SlmSessionId.Value != null)
            {
                string strSessionId = SlmSessionId.Value.ToString();
                var errtxt = string.Empty;
                username = LookCookie();
                if (BusService.Instance.Customer_SelectByUserNameAndPassword(username, strSessionId) != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }

        protected string LookCookie()
        {
            HttpCookie SlmMemberCookie = new HttpCookie("SLMFMembers");
            SlmMemberCookie = HttpContext.Request.Cookies["SLMFMembers"];
            string strUser = "";
            if (SlmMemberCookie != null && SlmMemberCookie.Value != "" &&
                 SlmMemberCookie.Value != null)
            {
                strUser = SlmMemberCookie.Value.ToString();
            }
            return strUser;
        }

		public GroupViewModel CreateViewModel(DataTransferViewModel dataTransfer)
		{
			GroupViewModel viewModel = new GroupViewModel();
			if (dataTransfer.EnumViewModelType.ToString().Contains("ADMIN"))
			{
                viewModel.CategoryModel = RetrieveAllCategoryViewModel(dataTransfer);
			}
            else if (dataTransfer.EnumViewModelType.ToString().Contains("HOME"))
            {
                viewModel.CategoryModel = RetrieveAllCategoryViewModel(dataTransfer);
                viewModel.AllItemModel = RetrieveAllItemViewModel(dataTransfer);

                // Add it to the shopping cart 
                var cart = ShoppingCart.GetCart(this.HttpContext);
                // Set up shoppingCart ViewModel
                viewModel.ShoppingCartModel = new ShoppingCartViewModel
                {
                    CartItems = cart.GetCartItems(),
                    CartTotal = cart.GetTotal()
                };

                var username = string.Empty;
                if ((username = LookCookie()) != string.Empty)
                {
                    viewModel.UsersModel = RetrieveUsersByUserNameViewModel(username);
                }
            }
			switch (dataTransfer.EnumViewModelType)
			{
				case EnumViewModel.ADMIN_DETAILOF_CUSTOMER:
					break;
                case EnumViewModel.ADMIN_DETAILOF_ITEM:
                    viewModel.ItemModel = RetrieveDetailOfItemViewModel(dataTransfer);
                    viewModel.NationalPromotionModel = RetrieveNationalPromotionViewModel(dataTransfer);
                    viewModel.LocalPromotionModel = RetrieveLocalPromotionViewModel(dataTransfer);
                    viewModel.ChemistWareHouseModel = RetrieveChemistWareHouseViewModel(dataTransfer);
                    break;
				case EnumViewModel.ADMIN_CHEMISTWAREHOUSE:
					break;
				case EnumViewModel.ADMIN_ITEM:
                    viewModel.ItemModel = RetrieveItemViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_ORDERDETAIL:
                    viewModel.OrdersModel = RetrieveOrdersRevenueViewModel(dataTransfer);
                    viewModel.SelectedOrdersModel = RetrieveDetailOfOrdersViewModel(dataTransfer);
                    viewModel.OrderDetailModel = RetrieveOrderDetailViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_ROLEFUNCTIONS:
					break;
				case EnumViewModel.ADMIN_NATIONALPROMOTION:
					break;
				case EnumViewModel.ADMIN_LOCALPROMOTION:
					break;
				case EnumViewModel.ADMIN_EMPLOYEE:
					break;
				case EnumViewModel.ADMIN_DAILYREPORT:
                    viewModel.DailyReportModel = RetrieveDailyReportViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_WEEKLYREPORT:
                    viewModel.WeeklyReportModel = RetrieveWeeklyReportViewModel(dataTransfer);
					break;
				case EnumViewModel.ADMIN_CUSTOMER:
					break;
				case EnumViewModel.ADMIN_ORDERS:
					break;
				case EnumViewModel.ADMIN_CATEGORY:
					break;
				case EnumViewModel.ADMIN_FUNCTIONS:
					break;
				case EnumViewModel.ADMIN_ROLE:
					break;
                case EnumViewModel.ADMIN_ORDERS_REVENUE_EXECUTE:
                    viewModel.OrdersModel = RetrieveOrdersRevenueViewModel(dataTransfer);
                    break;
                case EnumViewModel.ADMIN_DETAILOF_DAILYREPORT:
                    viewModel.DailyReportModel = RetrieveDetailOfDailyReportViewModel(dataTransfer);
                    break;
                case EnumViewModel.ADMIN_DETAILOF_WEEKLYREPORT:
                    viewModel.WeeklyReportModel = RetrieveDetailOfWeeklyReportViewModel(dataTransfer);
                    break;
				case EnumViewModel.HOME_REGISTER:
					break;
				case EnumViewModel.HOME_DETAILOF_Customer:
					break;
                case EnumViewModel.HOME_INDEX:
                    dataTransfer.IDCategory = viewModel.CategoryModel.GetModel.LstObjModel[0].ID;
                    viewModel.ItemModel = RetrieveItemViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_CATEGORY:
                    viewModel.SelectedCategoryModel = RetrieveCategoryViewModel(dataTransfer);
                    viewModel.ItemModel = RetrieveItemViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_PRODUCT:
                    viewModel.ItemModel = RetrieveDetailOfItemViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_ACCOUNTINFO:
                    viewModel.CustomerModel = RetrieveLoginCustomerViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_ORDERHISTORY:
                    viewModel.OrdersModel = RetrieveOrdersViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_ORDERHISTORY_ORDERDETAIL:
                    viewModel.OrdersModel = RetrieveOrdersViewModel(dataTransfer);
                    viewModel.SelectedOrdersModel = RetrieveDetailOfOrdersViewModel(dataTransfer);
                    viewModel.OrderDetailModel = RetrieveOrderDetailViewModel(dataTransfer);
                    break;
			}
			return viewModel;
		}

		public bool UploadFile(HttpPostedFileBase file, string path, string name, ref string refName)
		{
			try
			{
				if (!System.IO.File.Exists(Server.MapPath(path + file.FileName)))
				{
					FileInfo f = new FileInfo(file.FileName);
					long ngay = DateTime.Now.ToBinary();
					refName = name + ngay + f.Extension;
					string fullPath = path + refName;
					if (file == null)
					return false;
					byte[] buffer = new byte[file.ContentLength];
					file.InputStream.Read(buffer, 0, file.ContentLength);
					FileStream newFile = new FileStream(Server.MapPath(fullPath), FileMode.Create, FileAccess.Write);
					newFile.Write(buffer, 0, file.ContentLength);
					newFile.Close();
				}
				else
				{
					refName = file.FileName;
				}
				return true;
			}
			catch
			{
				return false;
			}
		}

		public void DeleteFile(string filePath)
		{
			FileInfo file = new FileInfo(filePath);
			if (file.Exists)
			{
				file.Delete();
			}
		}

		public bool SendingMail(string subject, string emailContent, string to)
		{
			bool result = false;
			try
			{
				System.Net.Mail.SmtpClient mailclient = new System.Net.Mail.SmtpClient();
				System.Net.NetworkCredential auth = new System.Net.NetworkCredential(WebConfiguration.EmailLienHe, WebConfiguration.PasswordEmailLienHe);
				mailclient.Host = WebConfiguration.MailServer;
				mailclient.EnableSsl = true;
				mailclient.UseDefaultCredentials = true;
				mailclient.Credentials = auth;
				System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(WebConfiguration.EmailLienHe, to);
				mm.Subject = subject;
				mm.IsBodyHtml = true;
				mm.Body = emailContent;
				mailclient.Send(mm);
				result = true;
			}
			catch
			{
				result = false;
			}
			return result;
		}

        public WeeklyReportViewModel RetrieveDetailOfWeeklyReportViewModel(DataTransferViewModel dataTransfer)
        {
            var item = BusService.Instance.WeeklyReport_SelectByID(dataTransfer.IntID);
            var lst = new List<WeeklyReportDTO>();
            if (item != null)
            {
                lst.Add(item);
            }
            return new WeeklyReportViewModel
            {
                GetModel = new GetWeeklyReportViewModel
                {
                    LstObjModel = lst
                },
                EditModel = new EditWeeklyReportViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }

        public DailyReportViewModel RetrieveDetailOfDailyReportViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = new List<DailyReportDTO>();
            var item = BusService.Instance.DailyReport_SelectByID(dataTransfer.IntID);
            if (item != null)
            {
                lst.Add(item);
            }
            return new DailyReportViewModel
            {
                GetModel = new GetDailyReportViewModel
                {
                    LstObjModel = lst
                },
                EditModel = new EditDailyReportViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }

        public OrdersViewModel RetrieveOrdersRevenueViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = new List<OrdersDTO>();
            var chemistwarehouse = BusService.Instance.ChemistWareHouse_SelectAll().First(n => n.Name.ToUpper().Contains("ONLINE"));
            var lstOrder = BusService.Instance.Orders_SelectByIDChemistWareHouse(chemistwarehouse.ID).OrderByDescending(n => n.OrderDate);

            foreach (var item in lstOrder)
            {
                if (dataTransfer.From.Date <= item.OrderDate.Date && item.OrderDate.Date <= dataTransfer.To.Date)
                {
                    lst.Add(item);
                }
            }
            var totalitem = lst.Count;

            return new OrdersViewModel
            {
                GetModel = new GetOrdersViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddOrdersViewModel
                {
                },
                EditModel = new EditOrdersViewModel
                {
                    ID = dataTransfer.IntID,
                },
                ReferKeys = new OrdersReferKeys()
                {
                    From = dataTransfer.From,
                    To = dataTransfer.To
                },
                InfoText = dataTransfer.InfoText
            };
        }

        public OrdersViewModel RetrieveDetailOfOrdersViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = new List<OrdersDTO>();
            var item = BusService.Instance.Orders_SelectByID(dataTransfer.IDOrder);
            if (item != null)
            {
                lst.Add(item);
            }
            var totalitem = lst.Count;

            return new OrdersViewModel
            {
                GetModel = new GetOrdersViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddOrdersViewModel
                {
                },
                EditModel = new EditOrdersViewModel
                {
                },
                ReferKeys = new OrdersReferKeys()
                {
                }
            };
        }

		public ChemistWareHouseViewModel RetrieveChemistWareHouseViewModel(DataTransferViewModel dataTransfer)
		{
            var lst = new List<ChemistWareHouseDTO>();
            var item = BusService.Instance.ChemistWareHouse_SelectAll().First(n => n.Name.ToUpper().Contains("ONLINE"));
            if (item != null)
            {
                lst.Add(item);
            }
			return new ChemistWareHouseViewModel
			{
				GetModel = new GetChemistWareHouseViewModel
				{
					LstObjModel = lst,
                    TotalItem = lst.Count,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddChemistWareHouseViewModel
				{
				},
				EditModel = new EditChemistWareHouseViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public ItemViewModel RetrieveAllItemViewModel(DataTransferViewModel dataTransfer)
        {
            List<ItemDTO> lst = BusService.Instance.Item_SelectAll().ToList();
            int totalitem = lst.Count;

            return new ItemViewModel
            {
                GetModel = new GetItemViewModel
                {
                    LstObjModel = lst,
                    TotalItem = totalitem,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddItemViewModel
                {
                },
                EditModel = new EditItemViewModel
                {
                    ID = dataTransfer.IntID,
                },
                ReferKeys = new ItemReferKeys()
                {
                    IDCategory = dataTransfer.IDCategory,
                },
                InfoText = dataTransfer.InfoText
            };
        }

		public ItemViewModel RetrieveItemViewModel(DataTransferViewModel dataTransfer)
		{
			List<ItemDTO> lst = new List<ItemDTO>();
			int totalitem = lst.Count;
            if (dataTransfer.IDCategory != -1)
            {
                lst = BusService.Instance.Item_SelectByIDCategory(dataTransfer.IDCategory).ToList();
                totalitem = lst.Count;
            }
			return new ItemViewModel
			{
				GetModel = new GetItemViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddItemViewModel
				{
				},
				EditModel = new EditItemViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new ItemReferKeys()
				{
					IDCategory = dataTransfer.IDCategory,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public OrderDetailViewModel RetrieveOrderDetailViewModel(DataTransferViewModel dataTransfer)
		{
			List<OrderDetailDTO> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDOrder != -1)
			{
				lst = BusService.Instance.OrderDetail_SelectByIDOrder(dataTransfer.IDOrder).ToList();
                totalitem = lst.Count;
			}
			return new OrderDetailViewModel
			{
				GetModel = new GetOrderDetailViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddOrderDetailViewModel
				{
				},
				EditModel = new EditOrderDetailViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new OrderDetailReferKeys()
				{
					IDOrder = dataTransfer.IDOrder,
					IDItem = dataTransfer.IDItem,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public NationalPromotionViewModel RetrieveNationalPromotionViewModel(DataTransferViewModel dataTransfer)
		{
			List<NationalPromotionDTO> lst = new List<NationalPromotionDTO>();
			int totalitem = lst.Count;
			if (dataTransfer.IDItem != -1)
			{
                var item = BusService.Instance.NationalPromotion_SelectByIDItem(dataTransfer.IDItem);
                if (item != null)
                {
                    lst.Add(item);
                }
				totalitem = lst.Count;
			}
			return new NationalPromotionViewModel
			{
				GetModel = new GetNationalPromotionViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddNationalPromotionViewModel
				{
				},
				EditModel = new EditNationalPromotionViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new NationalPromotionReferKeys()
				{
					IDItem = dataTransfer.IDItem,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public LocalPromotionViewModel RetrieveLocalPromotionViewModel(DataTransferViewModel dataTransfer)
		{
			List<LocalPromotionDTO> lst =  new List<LocalPromotionDTO>();
			int totalitem = lst.Count;
            if (dataTransfer.IDItem != -1)
            {
                var item = BusService.Instance.LocalPromotion_SelectByIDItemAndIDChemistWareHouse(dataTransfer.IDItem, dataTransfer.IDChemistWareHouse);
                if (item != null)
                {
                    lst.Add(item);
                }
                totalitem = lst.Count;
            }

			return new LocalPromotionViewModel
			{
				GetModel = new GetLocalPromotionViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddLocalPromotionViewModel
				{
				},
				EditModel = new EditLocalPromotionViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new LocalPromotionReferKeys()
				{
					IDItem = dataTransfer.IDItem,
					IDChemistWareHouse = dataTransfer.IDChemistWareHouse,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public EmployeeViewModel RetrieveEmployeeViewModel(DataTransferViewModel dataTransfer)
		{
            var lst = new List<EmployeeDTO>
            {
                BusService.Instance.Employee_SelectByUserNameAndPassword(dataTransfer.UserName, dataTransfer.Password)
            };

			return new EmployeeViewModel
			{
				GetModel = new GetEmployeeViewModel
				{
                    LstObjModel = lst,
                    TotalItem = lst.Count,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddEmployeeViewModel
				{
				},
				EditModel = new EditEmployeeViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new EmployeeReferKeys()
				{
					IDRole = dataTransfer.IDRole,
					IDChemistWareHouse = dataTransfer.IDChemistWareHouse,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public DailyReportViewModel RetrieveDailyReportViewModel(DataTransferViewModel dataTransfer)
		{
			List<DailyReportDTO> lst = new List<DailyReportDTO>();
			int totalitem = -1;
			if (dataTransfer.IDChemistWareHouse != -1 && dataTransfer.ReportDate != DateTime.MinValue)
			{
                var item = BusService.Instance.DailyReport_SelectByIDChemistWareHouseAndReportDate(dataTransfer.IDChemistWareHouse, dataTransfer.ReportDate);
                if(item != null)
                {
                    lst.Add(item);
                }
			}
			else if (dataTransfer.IDChemistWareHouse != -1)
			{
                lst = BusService.Instance.DailyReport_SelectByIDChemistWareHouse(dataTransfer.IDChemistWareHouse).ToList();
			}

            totalitem = lst.Count;
			
            return new DailyReportViewModel
			{
				GetModel = new GetDailyReportViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddDailyReportViewModel
				{
				},
				EditModel = new EditDailyReportViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new DailyReportReferKeys()
				{
					IDChemistWareHouse = dataTransfer.IDChemistWareHouse,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public WeeklyReportViewModel RetrieveWeeklyReportViewModel(DataTransferViewModel dataTransfer)
		{
			List<WeeklyReportDTO> lst = null;
			int totalitem = -1;
            if (dataTransfer.IDChemistWareHouse != -1 && dataTransfer.StartReportDate != DateTime.MinValue && dataTransfer.EndReportDate != DateTime.MinValue)
            {
                var item = BusService.Instance.WeeklyReport_SelectByIDChemistWareHouseAndReportDate(dataTransfer.IDChemistWareHouse, dataTransfer.StartReportDate, dataTransfer.EndReportDate);
                if (item != null)
                {
                    lst.Add(item);
                }
			}
			else if (dataTransfer.IDChemistWareHouse != -1)
			{
                lst = BusService.Instance.WeeklyReport_SelectByIDChemistWareHouse(dataTransfer.IDChemistWareHouse).ToList();
			}

            totalitem = lst.Count;

			return new WeeklyReportViewModel
			{
				GetModel = new GetWeeklyReportViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddWeeklyReportViewModel
				{
				},
				EditModel = new EditWeeklyReportViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new WeeklyReportReferKeys()
				{
					IDChemistWareHouse = dataTransfer.IDChemistWareHouse,
				},
				InfoText = dataTransfer.InfoText
			};
		}

		public OrdersViewModel RetrieveOrdersViewModel(DataTransferViewModel dataTransfer)
		{
			List<OrdersDTO> lst = null;
			int totalitem = -1;
			
            if (dataTransfer.IDChemistWareHouse != -1)
			{
                lst = BusService.Instance.Orders_SelectByIDChemistWareHouse(dataTransfer.IDChemistWareHouse).ToList();
			}
			else if (dataTransfer.IDCustomer != -1)
			{
                lst = BusService.Instance.Orders_SelectByIDCustomer(dataTransfer.IDCustomer).ToList();
			}

            totalitem = lst.Count;

			return new OrdersViewModel
			{
				GetModel = new GetOrdersViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddOrdersViewModel
				{
				},
				EditModel = new EditOrdersViewModel
				{
					ID = dataTransfer.IntID,
				},
				ReferKeys = new OrdersReferKeys()
				{
					IDChemistWareHouse = dataTransfer.IDChemistWareHouse,
					IDCustomer = dataTransfer.IDCustomer,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public CategoryViewModel RetrieveAllCategoryViewModel(DataTransferViewModel dataTransfer)
        {
            List<CategoryDTO> lst = BusService.Instance.Category_SelectAll().ToList();

            return new CategoryViewModel
            {
                GetModel = new GetCategoryViewModel
                {
                    LstObjModel = lst,
                    TotalItem = lst.Count,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddCategoryViewModel
                {
                },
                EditModel = new EditCategoryViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }

		public CategoryViewModel RetrieveCategoryViewModel(DataTransferViewModel dataTransfer)
		{
            var lst = new List<CategoryDTO>();
            var item = BusService.Instance.Category_SelectByID(dataTransfer.IDCategory);
            if(item != null)
            {
                lst.Add(item);
            }
			return new CategoryViewModel
			{
				GetModel = new GetCategoryViewModel
				{
                    LstObjModel = lst,
                    TotalItem = lst.Count,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddCategoryViewModel
				{
				},
				EditModel = new EditCategoryViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public CustomerViewModel RetrieveLoginCustomerViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = new List<CustomerDTO>
            { 
                BusService.Instance.Customer_SelectByUserName(dataTransfer.UserName)
            };
            return new CustomerViewModel
            {
                GetModel = new GetCustomerViewModel
                {
                    LstObjModel = lst,
                    TotalItem = lst.Count,
                    CurrentPage = dataTransfer.CurrentPage
                },
                AddModel = new AddCustomerViewModel
                {
                },
                EditModel = new EditCustomerViewModel
                {
                    ID = dataTransfer.IntID,
                }
            };
        }

		public CustomerViewModel RetrieveCustomerViewModel(DataTransferViewModel dataTransfer)
		{
            var lst = BusService.Instance.Customer_SelectAll().ToList();
			return new CustomerViewModel
			{
				GetModel = new GetCustomerViewModel
				{
                    LstObjModel = lst,
					TotalItem = lst.Count,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddCustomerViewModel
				{
				},
				EditModel = new EditCustomerViewModel
				{
					ID = dataTransfer.IntID,
				}
			};
		}

        public CustomerViewModel RetrieveUsersByUserNameViewModel(string username)
        {
            var lst = new List<CustomerDTO>();
            var item = BusService.Instance.Customer_SelectByUserName(username);
            if (item != null)
            {
                lst.Add(item);
            }
            return new CustomerViewModel
            {
                GetModel = new GetCustomerViewModel
                {
                    LstObjModel = lst,
                    TotalItem = lst.Count,
                    CurrentPage = 1
                },
                AddModel = new AddCustomerViewModel
                {
                },
                EditModel = new EditCustomerViewModel
                {
                }
            };
        }

		public CustomerViewModel RetrieveDetailOfCustomerViewModel(DataTransferViewModel dataTransfer)
		{
            var lst = new List<CustomerDTO>();
            var item = BusService.Instance.Customer_SelectByID(dataTransfer.IntID);
            if (item != null)
            {
                lst.Add(item);
            }
			return new CustomerViewModel
			{
				GetModel = new GetCustomerViewModel
				{
                    LstObjModel = lst
				},
				EditModel = new EditCustomerViewModel
				{
					ID = dataTransfer.IntID,
				},
				InfoText = dataTransfer.InfoText
			};
		}

        public ItemViewModel RetrieveDetailOfItemViewModel(DataTransferViewModel dataTransfer)
        {
            var lst = new List<ItemDTO>();
            var item = BusService.Instance.Item_SelectByID(dataTransfer.IntID);
            if (item != null)
            {
                lst.Add(item);
            }
            return new ItemViewModel
            {
                GetModel = new GetItemViewModel
                {
                    LstObjModel = lst
                },
                EditModel = new EditItemViewModel
                {
                    ID = dataTransfer.IntID,
                },
                InfoText = dataTransfer.InfoText
            };
        }
	}
}